package com.recorder.recorder_lib.utils;

import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * desc   : 文件管理器
 * time   : 2018年12月21日16 : 30
 */
public class FileManager {
    private static String dirPath;

    public static void setDirPath(String dirPath) {
        FileManager.dirPath = dirPath;
    }

    public static String getDirPath() {
        return Environment.getExternalStorageDirectory().getAbsolutePath() + dirPath;
    }

    public static String createFilePath(long time) {
        String fileName = time + ".mp4";
        String filePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        return filePath + dirPath + fileName;
    }

    public static void init() {
        File folder = new File(Environment.getExternalStorageDirectory() + dirPath);
        if (!folder.exists()) folder.mkdir();
    }

    public static List<File> getFiles(String path) {
        File file = new File(path);
        if (file.exists()) {
            LinkedList<File> list = new LinkedList<>();
            File[] files = file.listFiles();
            for (File file2 : files) {
                if (!file2.isDirectory()) {
                    list.add(file2);
                }
            }
            return list;
        }
        return null;
    }

}